<template>
  <view class="cate">
			<view class="scroll-view-container">
				<scroll-view  scroll-y="true" class="left-scroll-view"  :style="{height: wh+'px'}">
					<view  :class="['left-scroll-view-item',cur_active==index ? 'active' :'' ]"   v-for="(item1,index) in cat_list" :key="index" @click="clickScroll(index)">{{item1.cat_name}}</view>
				</scroll-view>
				<scroll-view  scroll-y="true" class="right-scroll-view"  :style="{height: wh+'px'}">
					<view class="cate-lv2" v-for="(item2,index) in cate_lv2" :key="index">
						<view class="cate-lv2-title"   > 
							/ {{item2.cat_name}} /
						</view>
						<view class="cate-lv3-list">
							<view class="cate-lv3-item"  v-for="(item3,index) in item2.children" :key="index" @click="goodsList(item3)">
								 <image :src="item3.cat_icon"></image>
									<text>{{item3.cat_name}}</text>
									
							</view>
							
						</view>
					</view>
				</scroll-view>
			</view>

  </view>
</template>
<script>
	export default {
		data() {
			return {
				wh:'',
				cat_list:'',
				cur_active:0,
				cate_lv2:'',
				cate_lv3:''
			}
		},
		onLoad(){
			// 获取当前系统设备
			const sysInfo=uni.getSystemInfo()
			this.wh=sysInfo.windowHeight //得到当前设备的可用高度
			this.getCategories()
		},
		methods: {
			async getCategories(){
				let res =await uni.$http.get('/api/public/v1/categories')	
				console.log(res)
				if(res.statusCode==200){
					this.cat_list=res.data.message
					this.cate_lv2=res.data.message[0].children
				}
			},
			clickScroll(index){
				this.cur_active=index
				this.cate_lv2=this.cat_list[index].children
			},
			goodsList(item3){
				console.log(item3)
				uni.navigateTo({
					url:'../../subpkg/goods_list/goods_list?cid='+item3.cat_id
				})
			}
		}
			
		
	}
</script>

<style lang="scss">
.scroll-view-container{
	display: flex;
	.left-scroll-view{
		// height: 2000rpx;
		width: 120px;
		.left-scroll-view-item{
			line-height:60px;
			background-color: #f7f7f7;
			text-align: center;
			font-size: 12px;
			&.active{
				background-color: #fff;
				position: relative;
				// 激活样式左侧的红色指示线
				&::before{
					content:'';
					width: 3px;
					background-color: #c00000;
					display: block;
					height: 30px;
					position: absolute;
					left: 0;
					top:50%;
					transform: translateY(-50%);
				}
			}
		}
	}
	.right-scroll-view{
		flex:1;
		.cate-lv2{
			.cate-lv2-title{
				text-align: center;
				font-size: 12px;
				padding: 15px 0;
				font-weight: bold;
			}
			.cate-lv3-list{
				display: flex;
				flex-wrap: wrap;
				.cate-lv3-item {
					width: 33.33%;
					margin-bottom: 10px;
					display: flex;
					flex-direction: column;
					align-items: center;
					image{
						width: 60px;
						height: 60px;
					}
					text{
						font-size: 12px;
					}
				}
			}
		}
	}
}

	
</style>
